package common

import (
	"ginessential/model"

	"gorm.io/driver/postgres"

	"gorm.io/gorm"
)

var DB *gorm.DB

func InitDB() *gorm.DB {
	dsn := "host=localhost user=postgres password=system dbname=mbtisystem port=5432"
	db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("failed to connet database, err :" + err.Error())
	}
	db.AutoMigrate(&model.Student{}) //自动创建数据表
	DB = db
	return db
}

func GetDB() *gorm.DB {
	return DB
}
